class Solution
{
public:
    int distanceTraveled(int mainTank, int additionalTank)
    {
        int distance = 0;
        while (true)
        {
            if (mainTank >= 5)
            {
                if (additionalTank > 0)
                {
                    mainTank -= 4;
                    additionalTank -= 1;
                }
                else
                {
                    mainTank -= 5;
                }
                distance += 50;
            }
            else
            {
                distance += mainTank * 10;
                break;
            }
        }
        return distance;
    }
};